package com.see.services.impl;

import static com.see.util.SymbolUtil.findStaticDataFromSymbol;

import com.google.inject.Inject;
import com.see.domain.dao.StaticDataDao;
import com.see.domain.model.StaticData;
import com.see.domain.model.Symbol;
import com.see.network.api.StaticDataUpdator;
import com.see.services.api.DatasInitializer;

public class GoogleInitializerImpl implements DatasInitializer {

    private final StaticDataDao     staticDataDao;
    private final StaticDataUpdator staticDataUpdator;

    @Inject
    public GoogleInitializerImpl(StaticDataDao staticDataDao, StaticDataUpdator staticDataUpdator) {
        this.staticDataDao = staticDataDao;
        this.staticDataUpdator = staticDataUpdator;
    }

    public void initSymbolData(String[] symbols) {

        try {
            for (String symbol : symbols) {
                Symbol uptSymbol = staticDataUpdator.fetchSectorAndIndustryBySymbol(symbol.trim());
                StaticData staticData = findStaticDataFromSymbol(uptSymbol);
                staticDataDao.insert(staticData);
            }

        } catch (Exception e) {
            throw new RuntimeException("Cannot init google datas", e);
        }
    }

}
